package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.product.service.BaseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tangsy
 * @Description TODO
 * @date 2022/11/29 10:25
 * @Version 1.0
 */
@Api(tags = "三级分类")
@RestController
@RequestMapping("admin/product")
public class BaseCategoryController {

    @Autowired
    BaseCategoryService baseCategoryService;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

    @ApiOperation("一级分类查询")
    @GetMapping("getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> category1List = baseCategoryService.list();
        return Result.ok(category1List);
    }

    //admin/product/getCategory2/{category1Id}
    @ApiOperation("二级分类查询")
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id){
        List<BaseCategory2> category2List = baseCategory2Service.getCategory2ByC1Id(category1Id);
        return Result.ok(category2List);
    }

    //admin/product/getCategory3/{category2Id}
    @ApiOperation("三级分类查询")
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> category3List = baseCategory3Service.getCategory3ByC2Id(category2Id);
        return Result.ok(category3List);
    }

    //admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}


}
